#if !defined(_DBFEXEPTION_H__INCLUDED_)
#define _DBFEXEPTION_H__INCLUDED_

#define NO_TG_DBF_ERROR                        0
#define TG_DBF_ERROR_MIN                       3000
#define TG_DBF_ERROR                           TG_DBF_ERROR_MIN
#define TG_DBF_ERROR_DBFILE_CREATE		        TG_DBF_ERROR+1
#define TG_DBF_ERROR_DBFILE_OPEN		        TG_DBF_ERROR+2
#define TG_DBF_ERROR_DBFILE_MEMORYLOAD			TG_DBF_ERROR+3
#define TG_DBF_ERROR_DBFHEADER_READ				TG_DBF_ERROR+4
#define TG_DBF_ERROR_DBFHEADER_WRITE			TG_DBF_ERROR+5
#define TG_DBF_ERROR_NOT_TABLE					TG_DBF_ERROR+6
#define TG_DBF_ERROR_NOT_FIELDS					TG_DBF_ERROR+7
#define TG_DBF_ERROR_FILE_SIZE					TG_DBF_ERROR+8
#define TG_DBF_ERROR_FIELDS_READ				TG_DBF_ERROR+9
#define TG_DBF_ERROR_MEMO_OPEN					TG_DBF_ERROR+10
#define TG_DBF_ERROR_MEMO_HEAD_READ				TG_DBF_ERROR+11
#define TG_DBF_ERROR_MEMO_BLOCK_SIZE			TG_DBF_ERROR+12
#define TG_DBF_ERROR_MEMO_FIELD_READ			TG_DBF_ERROR+13
#define TG_DBF_ERROR_MEMO_FIELD_WRITE			TG_DBF_ERROR+14
#define TG_DBF_ERROR_MEMO_RECORD_READ			TG_DBF_ERROR+15
#define TG_DBF_ERROR_MEMO_RECORD_WRITE			TG_DBF_ERROR+16
#define TG_DBF_ERROR_RECORD_OUTOFRANGE			TG_DBF_ERROR+17
#define TG_DBF_ERROR_RECORD_READ				TG_DBF_ERROR+18
#define TG_DBF_ERROR_RECORD_WRITE				TG_DBF_ERROR+19
#define TG_DBF_ERROR_MAX						TG_DBF_ERROR+19

// Logging helpers

#ifdef _DEBUG
BOOL TGAssertFailedLine(LPCSTR lpszDBFCall, LPCSTR lpszFile, int nLine);
#define DBF_CHECK_ERROR(f, err) if (!(f)) return FALSE;
// 	do \
// 	{ \
// 	if(!(f)) \
// 	 if(TGAssertFailedLine(#f,THIS_FILE, __LINE__)) \
// 		{ AfxDebugBreak(); }\
// 	 else TGThrowDBFException(err);\
// 	} \
// 	while (0)

#else
#define DBF_CHECK_ERROR(f, err) if(!(f)) return FALSE;

		//TGThrowDBFException(err);
		

#endif // _DEBUG
// Info structures

struct CDBFErrorInfo
{
// Attributes
	long	m_lErrorCode;
	CString	m_strDescription;

#ifdef _DEBUG
	virtual void Dump(CDumpContext& dc) const;
#endif
};

class TDBFUTILITY_IMPEXP CDBFException : public CException
{
	DECLARE_DYNAMIC(CDBFException)

public:
	CDBFException();

public:
	CDBFErrorInfo* m_pErrorInfo;

	long m_nTGDBFError;

public:
	void GetErrorInfo(/*int nIndex*/);
public:
	virtual ~CDBFException();
	virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
		PUINT pnHelpContext = NULL);

protected:
	void FillErrorInfo();
};

void AFXAPI TGThrowDBFException(long nTGDBFError = NO_TG_DBF_ERROR);

//{{AFX_INSERT_LOCATION}}
#endif // !defined(_DBFEXEPTION_H__INCLUDED_)

